using System;

namespace WenYu.Core.CodeGen
{
    /// <summary>
    /// 中间代码(IR)操作码定义 - 对齐.NET IL指令集
    /// 
    /// 文语编译器的IR使用栈式虚拟机架构：
    /// - 操作数通过栈进行传递
    /// - 结果压入栈顶
    /// - 符号表管理变量
    /// 
    /// 命名规范：遵循.NET IL指令命名，便于JIT编译实施
    /// 
    /// 对标需求: REQ-04 代码生成器
    /// </summary>
    public enum IROpcode
    {
        // ===== 常量加载 (Load Constant) =====
        /// <summary>Ldc_I4 - Load constant int32 (加载整数常量) | 对应IL: ldc.i4</summary>
        Ldc_I4,
        
        /// <summary>Ldc_R8 - Load constant float64 (加载浮点数常量) | 对应IL: ldc.r8</summary>
        Ldc_R8,
        
        /// <summary>Ldstr - Load string (加载字符串常量) | 对应IL: ldstr</summary>
        Ldstr,
        
        // 注意：LOAD_BOOL已合并到Ldc_I4，布尔值用0/1表示
        
        // ===== 变量操作 (Local Variable) =====
        /// <summary>Stloc - Store local variable (存储局部变量) | 对应IL: stloc</summary>
        Stloc,
        
        /// <summary>Ldloc - Load local variable (加载局部变量) | 对应IL: ldloc</summary>
        Ldloc,
        
        // ===== 算术运算 (Arithmetic) =====
        /// <summary>Add - Addition (加法) | 对应IL: add</summary>
        Add,
        
        /// <summary>Sub - Subtraction (减法) | 对应IL: sub</summary>
        Sub,
        
        /// <summary>Mul - Multiplication (乘法) | 对应IL: mul</summary>
        Mul,
        
        /// <summary>Div - Division (除法) | 对应IL: div</summary>
        Div,
        
        /// <summary>Rem - Remainder (取余) | 对应IL: rem</summary>
        Rem,
        
        // ===== 比较运算 (Comparison) =====
        /// <summary>Ceq - Compare equal (相等比较) | 对应IL: ceq</summary>
        Ceq,
        
        /// <summary>Cne - Compare not equal (不相等比较) | 虚拟指令: ceq + not</summary>
        Cne,
        
        /// <summary>Clt - Compare less than (小于比较) | 对应IL: clt</summary>
        Clt,
        
        /// <summary>Cle - Compare less or equal (小于等于比较) | 虚拟指令: cgt + not</summary>
        Cle,
        
        /// <summary>Cgt - Compare greater than (大于比较) | 对应IL: cgt</summary>
        Cgt,
        
        /// <summary>Cge - Compare greater or equal (大于等于比较) | 虚拟指令: clt + not</summary>
        Cge,
        
        // ===== 逻辑运算 (Logical) =====
        /// <summary>And - Logical AND (逻辑与) | 对应IL: and</summary>
        And,
        
        /// <summary>Or - Logical OR (逻辑或) | 对应IL: or</summary>
        Or,
        
        /// <summary>Not - Logical NOT (逻辑非) | 对应IL: not</summary>
        Not,
        
        // ===== 控制流 (Control Flow) =====
        /// <summary>Br - Unconditional branch (无条件跳转) | 对应IL: br</summary>
        Br,
        
        /// <summary>Brfalse - Branch if false (假时跳转) | 对应IL: brfalse</summary>
        Brfalse,
        
        /// <summary>Br_Break - Break out of loop (跳出循环) | 语义扩展: br</summary>
        Br_Break,
        
        /// <summary>Br_Continue - Continue loop (继续循环) | 语义扩展: br</summary>
        Br_Continue,
        
        // ===== 函数调用 (Method Call) =====
        /// <summary>Call - Call method (调用函数) | 对应IL: call</summary>
        Call,
        
        /// <summary>Ret - Return (返回) | 对应IL: ret</summary>
        Ret,
        
        /// <summary>Call_Print - Print to console (输出到控制台) | 语义扩展: call Console.WriteLine</summary>
        Call_Print,
        
        // ===== 栈操作 (Stack) =====
        /// <summary>Pop - Pop stack (弹出栈顶) | 对应IL: pop</summary>
        Pop,
        
        /// <summary>Dup - Duplicate stack top (复制栈顶) | 对应IL: dup</summary>
        Dup,
        
        // ===== 数组操作 (Array) =====
        /// <summary>Newarr - Create new array (创建数组) | 对应IL: newarr</summary>
        Newarr,
        
        /// <summary>Ldelem - Load array element (读取数组元素) | 对应IL: ldelem</summary>
        Ldelem,
        
        /// <summary>Stelem - Store array element (写入数组元素) | 对应IL: stelem</summary>
        Stelem,
        
        // ===== 对象操作 (Object) =====
        /// <summary>Newobj - Create new object (创建对象) | 对应IL: newobj</summary>
        Newobj,
        
        /// <summary>Ldfld - Load field (读取字段) | 对应IL: ldfld</summary>
        Ldfld,
        
        /// <summary>Stfld - Store field (写入字段) | 对应IL: stfld</summary>
        Stfld,
        
        /// <summary>Callvirt - Call virtual method (调用虚方法) | 对应IL: callvirt</summary>
        Callvirt,
    }
}
